﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Cua_Hang.DTO;
using System.Data;

namespace Cua_Hang.DAO
{
    public class DangNhap_DAO
    {
        //----------load tat ca nhan vien  ------------
        public static List<DangNhap_DTO> Load_All_NhanVien_DAO( DangNhap_DTO dn)
        {
            try
            {
                DataProvider d = new DataProvider();
                String strSQL = "SELECT * FROM NhanVien WHERE user_nhanvien = N'" + dn.User_nhanvien + "' AND pass_nhanvien = N'" + dn.Pass_nhanvien + "'";
                DataTable dt = d.ExecuteQuery(strSQL);

                List<DangNhap_DTO> lstCuaHang = new List<DangNhap_DTO>();
                foreach (DataRow dr in dt.Rows)
                {
                    DangNhap_DTO dm = new DangNhap_DTO();
                    dm.ID_cuahang = (int)dr["ID_cuahang"];
                    dm.ID_NhanVien = Convert.ToInt32(dr["ID_NhanVien"].ToString());
                    dm.User_nhanvien = dr["user_nhanvien"].ToString();
                    dm.User_nhanvien = dr["pass_nhanvien"].ToString();


                    lstCuaHang.Add(dm);
                }
                return lstCuaHang;
            }
            catch (Exception ex)
            {
                throw new Exception("Loi!!" + ex.Message);
            }
        }

        //-------ket thuc -load tat ca nhan vien------------
        //==================================================================
        //==============================================================
        //------ ham kiem tra dang nhap------------
        public static Boolean KiemTra_DangNhap_DAO(DangNhap_DTO dn)
        {
            Boolean kq = false;
            try
            {
                DataProvider d = new DataProvider();
                String strSQL = "SELECT * FROM NhanVien WHERE user_nhanvien = N'" + dn.User_nhanvien + "' AND pass_nhanvien = N'" + dn.Pass_nhanvien + "'";
                DataTable dt = d.ExecuteQuery(strSQL);
                if (dt.Rows.Count > 0)
                {
                    kq = true;
                }

            }
            catch (Exception ex)
            {
                throw new Exception("Loi!!" + ex.Message);
            }
            return kq;
        }
        //-------ket thuc ham kiem tra dang nhap -----------





    }
}